<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>ajax 封装</title>
    <script src="../js/ajax.js"></script>
</head>
<body>
    <button class="get">GET 请求数据</button>
    <button class="post">post 请求数据</button>
    

    <script>
        // ajax  封装
        // promise 铺垫  
        var getbtn = document.getElementsByClassName("get")[0];
        var postbtn = document.getElementsByClassName("post")[0];
        
        // get请求 
        getbtn.onclick = function(){
            $.ajax({
                type:"get",
                url:"../php/register_get.php",
                data:{
                    user:"helloqa",
                    pass:"abc123",
                    phone:"180999776655",
                    email:"qwerty@111.com",
                },   // 请求发送到服务器的数据
                dataType:'json',
                success:function(result){  //result 形参(请求成功时候返回的数据)
                    console.log(result)
                }
            })
        }
        
        // post 请求 
        postbtn.onclick = function(){
            var user = "heelo"
            var pass = "aa"

            $.post({
                
                url:"../php/login.php",
                data:{
                    user,
                    pass
                },
                // async:true,
                dataType:"json",
                success:result=>{
                    console.log(result)
                }
            })
        }



        
    </script>
</body>
</html>